/** Copyright (c) 2015—2017 Zerone.Co.Ltd. All rights reserved. */
package com.zerone.facade.merchant.enums;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

/** @author glassescat <a href="">零一零一科技</a> */
public enum MerchantTypeEnum {
  AGENT_MERCHANT("AGENT_MERCHANT", "代理商户"),

  NORMAL_MERCHANT("NORMAL_MERCHANT", "普通商户"),
  ;

  /** 枚举值 */
  private final String code;

  /** 枚举描述 */
  private final String message;

  public static Map<String, String> mappingMerchantType() {
    MerchantTypeEnum[] merchantTypes = values();
    return new HashMap<String,String>(){{
      Arrays.stream(merchantTypes).forEach(merchantType -> put(merchantType.code,merchantType.message));
    }};
  }

  /**
   * @param code 枚举值
   * @param message 枚举描述
   */
  MerchantTypeEnum(String code, String message) {
    this.code = code;
    this.message = message;
  }

  /** @return Returns the code. */
  public String getCode() {
    return code;
  }

  /** @return Returns the message. */
  public String getMessage() {
    return message;
  }

  /** @return Returns the code. */
  public String code() {
    return code;
  }

  /** @return Returns the message. */
  public String message() {
    return message;
  }

  /**
   * 通过枚举<code>code</code>获得枚举
   *
   * @param code
   * @return MerchantTypeEnum
   */
  public static MerchantTypeEnum getByCode(String code) {
    for (MerchantTypeEnum _enum : values()) {
      if (_enum.getCode().equals(code)) {
        return _enum;
      }
    }
    return null;
  }

  /**
   * 获取全部枚举
   *
   * @return List<MerchantTypeEnum>
   */
  public static java.util.List<MerchantTypeEnum> getAllEnum() {
    java.util.List<MerchantTypeEnum> list =
        new java.util.ArrayList<MerchantTypeEnum>(values().length);
    for (MerchantTypeEnum _enum : values()) {
      list.add(_enum);
    }
    return list;
  }

  /**
   * 获取全部枚举值
   *
   * @return List<String>
   */
  public static java.util.List<String> getAllEnumCode() {
    java.util.List<String> list = new java.util.ArrayList<String>(values().length);
    for (MerchantTypeEnum _enum : values()) {
      list.add(_enum.code());
    }
    return list;
  }

  /**
   * 通过code获取msg
   *
   * @param code 枚举值
   * @return
   */
  public static String getMsgByCode(String code) {
    if (code == null) {
      return null;
    }
    MerchantTypeEnum _enum = getByCode(code);
    if (_enum == null) {
      return null;
    }
    return _enum.getMessage();
  }

  /**
   * 获取枚举code
   *
   * @param _enum
   * @return
   */
  public static String getCode(MerchantTypeEnum _enum) {
    if (_enum == null) {
      return null;
    }
    return _enum.getCode();
  }
}
